package com.ruoyi.statistical.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.employment.domain.EmploymentInfo;
import com.ruoyi.employment.service.IEmploymentInfoService;
import com.ruoyi.statistical.domain.StatisticalInfo;
import com.ruoyi.student.service.IStudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.security.PublicKey;
import java.util.List;


/**
 * @projectName: employmentSystem
 * @package: com.ruoyi.statistical.controller
 * @className: StatisticalController
 * @author: ximu
 * @description: TODO
 * @date: 2022/5/18 10:42
 * @version: 1.0
 */
@RestController
@RequestMapping("/statistical")
@CrossOrigin
public class StatisticalController{

    @Autowired
    private IEmploymentInfoService employmentInfoService;

    @Autowired
    private IStudentInfoService studentInfoService;

    @GetMapping("findAllStatistical")
    public StatisticalInfo list() {
        //对口统计
        int counterpart = 0;
        double counterpartrRate;
        //核心对口统计
        int coreCounterpart = 0;
        double coreCounterRate;
        //非对口
        int notCounterpart = 0;
        double notCounterpartrRate;

        List<EmploymentInfo> list = employmentInfoService.selectEmploymentInfoList2();
        System.out.println(list.size());
        for (EmploymentInfo employmentInfo: list) {
            if (employmentInfo.getCounterpart() == 1){
                counterpart++;
                if(employmentInfo.getCoreCounterpart() == 1){
                    coreCounterpart++;
                }
            }
        }
        counterpartrRate = ((double)counterpart)/list.size();
        System.out.println(counterpartrRate);
        coreCounterRate = ((double)coreCounterpart)/list.size();
        System.out.println(coreCounterRate);
        notCounterpartrRate = ((double) (list.size()-counterpart))/list.size();
        System.out.println(notCounterpartrRate);
        StatisticalInfo  sl = new StatisticalInfo("常德职业技术学院",counterpartrRate,coreCounterRate,notCounterpartrRate);
        return sl;
    }


}
